using System.Collections;
using DG.Tweening;
using UnityEngine;

// 伤害系统
public class DamageSystem : MonoBehaviour
{
    [SerializeField] private Transform knife;    // 匕首对象
    [SerializeField] private Health health;     // 生命值组件

    private void OnEnable()
    {
        // 注册伤害动作执行器
        ActionSystem.AttachPerformer<DealDamageGA>(DealDamagePerformer);
    }

    void OnDisable()
    {
        // 注销伤害动作执行器
        ActionSystem.DetachPerformer<DealDamageGA>();
    }

    // 伤害动作的具体执行逻辑
    private IEnumerator DealDamagePerformer(DealDamageGA dealDamageGA)
    {
        int damageAmount = dealDamageGA.Amount;
        Vector2 knifeStart = knife.transform.position;

        // 匕首攻击动画
        Tween tween = knife.transform.DOMove(health.transform.position, 0.25f);
        yield return tween.WaitForCompletion();

        // 匕首返回动画
        knife.transform.DOMove(knifeStart, 0.5f);

        // 实际扣血逻辑
        yield return health.ReduceHealth(damageAmount);
    }
}